﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using Microsoft.SharePoint.Administration;
using System.Data;

namespace SpugPt.DataConnManager
{
    public class Helper 
    {
        public  const string PREFIX = "spugptdataconn_";
        /// <summary>
        /// Creates the data table.
        /// </summary>
        /// <returns></returns>
        public static DataTable CreateDataTable()
        {
            DataTable dt = new DataTable();
            dt.Columns.Add(new DataColumn("Key", typeof(string)));
            dt.Columns.Add(new DataColumn("Name", typeof(string)));
            dt.Columns.Add(new DataColumn("Value", typeof(string)));
            return dt;
        }
        /// <summary>
        /// Gets the web app.
        /// </summary>
        /// <param name="webId">The web id.</param>
        /// <returns></returns>
        public static  SPWebApplication GetWebApp(string webId)
        {
            SPServiceCollection services = SPFarm.Local.Services;
            SPWebApplication webAppFound = null;

            foreach (SPService curService in services)
            {
                if (curService is SPWebService)
                {
                    SPWebService webService = (SPWebService)curService;
                    foreach (SPWebApplication webApp in webService.WebApplications)
                    {
                        if (webApp.Id.ToString() == webId)
                        {
                            webAppFound = webApp;
                            break;
                        }

                    }
                    if (webAppFound != null) break;
                }

            }
            return webAppFound;
        }

        
    }
        
    


}
